<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/5/30
 * Time: 13:56
 */
namespace app\api\controller;


use app\api\model\BalanceModel;
use app\api\model\BalancelogModel;
use think\Db;

class Balance extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->balance = new BalanceModel();
      	$this->balancelog = new BalancelogModel();
    }

    /**会员余额*/
    public function balance_list()
    {
        $data['uid'] = $this->uid;
        $balance_list = $this->balance->balancelist($data);
        //$balance_list['total'] = $balance_list['circulate']+$balance_list['circulation'];
       
      	AjaxReturn('1', '成功', ['data' => $balance_list]);
    }
	//会员流通币流水
    public function circulate()
    {
      	$uid = $this->uid;
      	$type = request()->post('type');
        $res = $this->balancelog->where('balance_type',$type)->where('uid',$uid)->select();
        foreach ($res as $key=>$val)
        {
            switch ($val['type'])
            {
                case 1:
                    $res[$key]['type']='转入';
                    break;
                case 2:
                    $res[$key]['type']='转出';
                    break;
                case 3:
                    $res[$key]['type']='提现';
                    break;
                case 4:
                    $res[$key]['type']='买入';
                    break;
                case 5:
                    $res[$key]['type']='卖出';
                    break;
                case 6:
                    $res[$key]['type']='购买商品';
                    break;
                case 7:
                    $res[$key]['type']='实名';
                    break;
                case 8:
                    $res[$key]['type']='充值';
                    break;
                case 9:
                    $res[$key]['type']='兑换';
                    break;
                case 10:
                    $res[$key]['type']='释放';
                    break;
            }
            switch ($val['sign'])
            {
                case 1:
                    $res[$key]['sign']='+';
                    break;
                case 2:
                    $res[$key]['sign']='-';
                    break;
            }
           $res[$key]['createtime'] = date("Y-m-d H:i",$res[$key]['createtime']);
        }
      	$data['uid'] = $this->uid;
        $balance_list = $this->balance->balancelist($data);
      	if($res)
        {
           AjaxReturn('1', '成功', ['data' => $res,'balance_list'=>$balance_list]);
        }else{
        	AjaxReturn('0', '暂无更多数据' ,['balance_list'=>$balance_list]);
        }
    }
}
